package com.hackerrank.contests.sep13.challenges.chocolategame;

import java.util.ArrayList;
import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		long nw = 0, ce = 1, d[] = new long[N], c = 0, dc = 0;
		boolean so = false;
		for(int n = 0; n < N; n++) {
			d[n] = in.nextInt();
			if(so) {
				if(d[n] != d[n - 1]) {
					so = false;
					if(c % 2 == 0)
						dc += (c - 2) * (c - 2) / 4;
					else
						dc += (c - 1) * (c - 3) / 4;
				} else
					c++;
			} else if(d[n] % 2 == 1) {
				so = true;
				c = 1;
			}
		}
		if(so) {
			if(c % 2 == 0)
				dc += (c - 2) * (c - 2) / 4;
			else
				dc += (c - 1) * (c - 3) / 4;
		}
		ArrayList<Long> p = new ArrayList<Long>();
		for(int n = 0; n < N; n++) {
			if(d[n] % 2 == 1) {
				p.add(ce);
				ce = 1;
			} else
				ce++;
		}
		p.add(ce);
		long q[] = new long[p.size()];
		q[q.length - 1] = p.get(q.length - 1);
		q[q.length - 2] = p.get(q.length - 2);
		for(int i = q.length - 3; i >= 0; i--)
			q[i] = p.get(i) + q[i + 2];
		for(int i = 0; i < p.size() - 1; i++)
			nw += p.get(i) * q[i + 1];
		System.out.println(nw - p.size() + 1 - dc);
	}
}
